package com.hiray.restcache

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import com.google.gson.GsonBuilder
import com.hiray.restcache.api.RestApi
import com.hiray.restcache.api.RestApiHelper
import com.zmy.rxcache.RxCache
import es.dmoral.toasty.Toasty
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_index_promotion.*

class IndexPromotionActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_index_promotion)
        supportActionBar?.title = "活动"
    }

    override fun onResume() {
        super.onResume()

        val restApi = RestApiHelper.create()

        val subscribe = RxCache.Builder()
            .setCacheDir(cacheDir)
            .build()
            .create(restApi, RestApi::class.java)
            .getIndexActivities()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(Consumer{
                index_act_response_text.text =
                    GsonBuilder().setPrettyPrinting().create().toJson(it)
            })

    }
}